Conditions | 5 |
Total Lines | 59 |
Code Lines | 51 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | import React from 'react'; |
||
143 | |||
144 | render() { |
||
145 | const self = this; |
||
146 | const mainCols = this.props.columns.filter(column => !column.isChildRow); |
||
147 | const childCols = this.props.columns.filter(column => column.isChildRow); |
||
148 | |||
149 | const mainColsLength = this.props.showCheckbox ? mainCols.length + 1 : mainCols.length; |
||
150 | |||
151 | let rows = <tr><td colSpan={mainColsLength} style={{ 'text-align': 'center' }}>아이템이 없습니다.</td></tr>; |
||
152 | if (this.props.items.length > 0) { |
||
153 | rows = this.props.items.map((item, idx) => { |
||
154 | const checked = self.state.checkedItems.includes(item); |
||
155 | if (childCols.length > 0) { |
||
156 | return [ |
||
157 | <Row |
||
158 | className="main-row" |
||
159 | key={idx} |
||
160 | item={item} |
||
161 | columns={mainCols} |
||
162 | onCheckboxChange={(isChecked, targetItem) => this.onCheckboxChanged(isChecked, targetItem)} |
||
163 | checked={checked} |
||
164 | showCheckbox={this.props.showCheckbox} |
||
165 | />, |
||
166 | <ChildRow |
||
167 | item={item} |
||
168 | columns={childCols} |
||
169 | colSpan={mainCols.length} |
||
170 | checked={checked} |
||
171 | showCheckbox={this.props.showCheckbox} |
||
172 | />, |
||
173 | ]; |
||
174 | } |
||
175 | return ( |
||
176 | <Row |
||
177 | key={idx} |
||
178 | item={item} |
||
179 | columns={mainCols} |
||
180 | onCheckboxChange={(isChecked, targetItem) => this.onCheckboxChanged(isChecked, targetItem)} |
||
181 | checked={checked} |
||
182 | showCheckbox={this.props.showCheckbox} |
||
183 | /> |
||
184 | ); |
||
185 | }); |
||
186 | } |
||
187 | |||
188 | return ( |
||
189 | <BSTable responsive> |
||
190 | <thead> |
||
191 | <tr> |
||
192 | {this.props.showCheckbox ? ( |
||
193 | <th> |
||
194 | <Checkbox onChange={e => this.onCheckboxChanged(e.target.checked)} checked={this.state.allChecked} /> |
||
195 | </th> |
||
196 | ) : ''} |
||
197 | {mainCols.map((col, idx) => <th key={idx}>{col.title}</th>)} |
||
198 | </tr> |
||
199 | </thead> |
||
200 | <tbody>{rows}</tbody> |
||
201 | </BSTable> |
||
202 | ); |
||
222 |